<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #252525;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #ffffde;
            gap: 0 12px;
        }

        .container {
            background-color: inherit;
            position: relative;
            display: flex;
            align-items: center;
            flex-direction: column;
            overflow: hidden;
            width: 100px;
            height: 300px;
            mask-image: linear-gradient(180deg,
                    transparent,
                    #fff 20%,
                    #fff 80%,
                    transparent);
            /* mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent); */
            /* background-image: linear-gradient(180deg, transparent, blue 20%, purple 80%, transparent); */
        }

        .container div {
            white-space: nowrap;
            display: flex;
            flex-direction: column;
            animation: scrollUp var(--t) linear infinite;
            user-select: none;
        }

        .container div:nth-child(2) {
            animation: scrollUp2 var(--t) linear infinite;
            animation-delay: calc(var(--t) / -2);
            user-select: none;
        }

        @keyframes scrollUp {
            from {
                transform: translateY(100%);
            }

            to {
                transform: translateY(-100%);
            }
        }

        @keyframes scrollUp2 {
            from {
                transform: translateY(0%);
            }

            to {
                transform: translateY(-200%);
            }
        }

        .container div span {
            display: inline-flex;
            background-color: #333;
            letter-spacing: 0.2em;
            margin: 10px;
            border-radius: 5px;
            padding: 5px 10px;
        }
    </style>
</head>

<body>
    <!-- 第一列 -->
    <div class="container" style="--t: 16s">
        <div id="conghua">
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>

    <div class="container" style="--t: 12s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>

    <div class="container" style="--t: 8s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>

    <div class="container" style="--t: 4s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>
</body>
<script>
    const containers = document.querySelectorAll(".container");

    containers.forEach((container) => {
        let isDragging = false;
        let startY = 0;
        let initialTranslateY = 0;
        let currentTranslateY = 0;  // 当前translateY值
        const divs = container.querySelectorAll('div');  // 假设所有子元素是 divs

        // 处理鼠标拖动时的动作
        function moveFunc(e) {
            if (!isDragging) return;

            const deltaY = e.clientY - startY;  // 计算鼠标移动的距离
            const newTranslateY = initialTranslateY + deltaY; // 计算新的 translateY

            // 更新 divs 的位置
            divs.forEach((div) => {
                // div.style.transform = `translateY(${newTranslateY}px) !important`;  // 直接修改 transform
                div.style.transform = `translateY(${newTranslateY}px)`;  // 更新 translateY
            });
        }


        // 鼠标按下，开始拖动
        container.addEventListener('mousedown', (e) => {
            isDragging = true;
            startY = e.clientY;  // 获取鼠标按下时的 Y 坐标（相对于视口）
            initialTranslateY = currentTranslateY;  // 获取当前容器的 translateY 值
            container.style.cursor = 'grabbing';  // 设置拖动时的鼠标样式

            divs.forEach((div) => {
                div.style.animation = "none"
                div.style.transition = "none";  // 禁用过渡效果
                div.style.animationPlayState = "pause";  // 暂停动画
            });


            container.addEventListener('mousemove', moveFunc);

        });

        // 鼠标松开时，结束拖动
        container.addEventListener('mouseup', () => {
            isDragging = false;
            container.style.cursor = 'grab';  // 恢复鼠标样式

            // 恢复动画状态，恢复元素的动画
            // divs.forEach((div) => {
            //     div.style.transition = "";  // 恢复过渡
            //     div.style.animationPlayState = "running";  // 恢复动画
            // });

            container.removeEventListener('mousemove', moveFunc);

            // 更新当前的 translateY 值，确保动画从新位置继续
            divs.forEach((div) => {
                const computedStyle = window.getComputedStyle(div);
                const transform = computedStyle.transform;
                const translateYMatch = transform.match(/matrix\([^\)]+,\s([-\d.]+)/);
                if (translateYMatch) {
                    currentTranslateY = parseFloat(translateYMatch[1]);
                }
            });
        });

        // 鼠标离开容器时也结束拖动
        container.addEventListener('mouseleave', () => {
            if (isDragging) {
                isDragging = false;
                container.style.cursor = 'grab';  // 恢复鼠标样式
                container.removeEventListener('mousemove', moveFunc);  // 移除mousemove事件监听器
            }
        });
    });
</script>

</html>